import openai

openai.api_key = ...


def chat_demo(question):
    try:
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": question}
            ]
        )
        return response.choices[0].message.content.strip()
    except Exception as e:
        return f"Error occurred: {e}"


if __name__ == "__main__":
    print("Welcome to the GPT-3.5 Q&A System! Type 'exit' to quit.")
    while True:
        user_input = input("\nEnter your question: ")
        if user_input.lower() == "exit":
            print("Goodbye!")
            break

        answer = chat_demo(user_input)
        print(f"\nGPT-3.5's Answer: {answer}")
